<template>
	<view>
		<u-navbar title="分类 " :borderBottom="false" :background="background"> </u-navbar>
		<view class="top">
			<view class="list" @click="getactive(item.cid)" :class="active==item.cid?'active':''"
				v-for="(item,index) in cateList" :key="index">
				<view class="icon" v-if="active==item.cid"></view>
				<view class="name">
					{{item.cname}}
				</view>
			</view>
		</view>
		<view class="div"></view>
		<view class="content" v-if="list.length>0">
			<u-row>
				<u-col :span="6" v-for="(item,index) in list" :key="index">
					<view @click="toPage('details?pid='+item.pid)" :style="(index+1)%2==0?'margin-left: 0;':''"
						class="list">
						<u-lazy-load height="421" imgMode="scaleToFill" :borderRadius="20"
							:image="img_pre+item.thumbnail"></u-lazy-load>
						<view class="name omit">
							{{item.pname}}
						</view>
						<view class="text">
							{{item.price}}<text>蜂钻</text>
						</view>
					</view>
				</u-col>
			</u-row>
		</view>
		<view class="content" v-else>
			<view class="none" >
				<view class="none-view">
					<image src="../../../static/image/none.png" class="none-image"></image>
					<view class="none-name">
						该分类下暂无产品~
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var than;
	export default {
		data() {
			return {
				background: {
					background: 'transparent'
				},
				active: 0,
				cateList: [],
				page: 1,
				list: []
			}
		},
		onLoad(option) {
			than = this;
			than.active = option.cid
			than.post("/api/Product/cateList", null, function(data) {
				than.cateList = data
				than.getList();
			})
		},
		onReachBottom() {
			than.page++
			than.getList()
		},
		methods: {
			getactive(cid) {
				than.active = cid
				than.page = 1
				than.getList()
			},
			getList() {
				than.post("api/product/ProductList", {
					page: than.page,
					cid: than.active
				}, function(data) {
					if (than.page == 1) {
						than.list = data;
					} else {
						than.list = than.list.concat(data)
					}
				})
			},
		}
	}
</script>

<style lang="less">
	.top {
		position: fixed;
		top: 0;
		/* #ifdef APP-PLUS */
		padding-top: calc(100rpx + var(--status-bar-height));
		height: calc(180rpx + var(--status-bar-height));
		/* #endif */
		/* #ifdef H5 */
		padding-top: 100rpx;
		height: 180rpx;
		/* #endif */
		width: 100%;
		background: linear-gradient(180deg, #F5E4D4, #F6EEE6);

		z-index: 2;
		overflow: scroll;
		display: flex;
		white-space: nowrap;

		.active {
			font-size: 32rpx !important;
			color: #1D1916 !important;
		}

		.list {
			margin-left: 40rpx;
			display: flex;
			align-items: center;
			height: 50rpx;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #666666;

			.icon {
				background: #FE4D21;
				border-radius: 50%;
				width: 15rpx;
				height: 15rpx;
				margin-right: 15rpx;
			}
		}
	}

	.div {
		height: 200rpx;
		background: #F6EEE6;
	}

	.content {
		margin-top: -100rpx;
		z-index: 1;
		background: #FFFFFF;
		position: relative;
		width: 100%;
		border-radius: 70rpx 0px 0px 0px;
		padding-top: 28rpx;
		min-height: 100rpx;

		.list {
			width: 327rpx;
			margin-left: auto;
			margin-bottom: 30rpx;

			image {
				width: 327rpx;
				height: 437rpx;
				border-radius: 20rpx;
			}

			.name {
				margin-top: 10rpx;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #001111;
			}

			.text {
				margin-top: 10rpx;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #333333;

				text {
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #333333;
				}
			}
		}
	}
</style>
